/**格式化日期时间 */
const formatTime = (date, hide_MS = false) => {
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    // const second = date.getSeconds()
    if (hide_MS) {
        return [year, month, day].map(formatNumber).join('-')
    }
    // return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
    return [year, month, day].map(formatNumber).join('-') + '  ' + [hour, minute].map(formatNumber).join(':')
}

const formatNumber = n => {
    n = n.toString()
    return n[1] ? n : '0' + n
}

// 前端js注入，XSS安全问题解决
export const replaceStr = (str) => {
    return str.replace(/[<>"&\/`']/g, '')
}

export {
    formatTime
};